const { sys_announcement, op } = require('../../middleware/baseModel')

module.exports = {
  'GET /sys_announcement/dtl': async (ctx, next) => {
    const resList = await sys_announcement.findOne({ order: [['id', 'DESC']] })
    return ctx.success(resList)
  },

  'POST /sys_announcement/add': async (ctx, next) => {
    let row = ctx.getBody()
    let dbRow = await sys_announcement.findOne({ order: [['id', 'DESC']] })
    if (dbRow) {
      await dbRow.update(row)
    } else {
      await sys_announcement.create(row)
    }
    return ctx.success()
  },

  'POST /sys_announcement/edit': async (ctx, next) => {
    let row = ctx.getBody()
    let id = ctx.get('id')

    const resList = await sys_announcement.update(row, {
      where: {
        id: id
      }
    })
    return ctx.success(resList)
  },

}
